import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class main {
    public static void main(String[] args) {
        int[] coions = {2};
        Solution.coinChange(coions,3);
    }

    static class Solution {
        public static int coinChange(int[] coins, int amount) {
            Integer[] dp = new Integer[amount+1];


            dp[0] = 0;
            for(int i=1;i<dp.length;i++){
                dp[i]=-1;
            }
            for(int i=1;i<=amount;i++){
                for(int j:coins) {
                    if(i-j>=0) {
//                        dp[i] = min(flag,dp[i], dp[i - j] + 1);
                        int a = dp[i];
                        int b = dp[i - j];

                        if(a==-1){
                            if(b==-1){
                                dp[i] = -1;
                            }else{
                                dp[i] = b + 1;
                            }
                        }else{
                            if(b==-1){
                                dp[i] = dp[i];
                            }else{
                                dp[i] = a >= (b+1) ? (b+1) : a;
                               // System.out.println("i = " + i + ", j = " + j + ", dp = " + dp[i] + ", re = " + (i - j));
                            }
                        }
                    }
                }
            }
            return dp[amount];
        }
        public static int min(Boolean flag,Integer i,Integer j){
            if(i==-1){
                return j;
            }
            if(i>=j){
                flag=true;
            }
            return i>=j?j:i;
        }
    }
}
